package com.example.qxfw.hbqx.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.qx.ImportantWeather;
import com.example.qxfw.common.entity.qx.MsgMediumSmallScale;
import com.example.qxfw.common.entity.qx.MsgMediumSmallScaleTemp;
import com.example.qxfw.common.entity.qx.SmallScaleStation;
import com.example.qxfw.common.entity.zy.AirpolLiveQx;
import com.example.qxfw.common.entity.zy.EnviroStation;
import com.example.qxfw.common.util.DateUtil;
import com.example.qxfw.hbqx.service.QxjcService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;
import java.util.List;

@ApiIgnore
@Api(tags = "环保气象-气象监测")
@RestController
@CrossOrigin
@RequestMapping("/qxjc")
public class QxjcController {
    @Autowired
    private QxjcService qxjcService;

    @ApiOperation("降序获取观测时间")
    @GetMapping(value = "/getObservtime")
    public SysResult getObservtime(){
        List<AirpolLiveQx> observtime = qxjcService.getObservtime();
        return SysResult.success(observtime);
    }

    @ApiOperation("根据市县和站点id查询站点名字和id")
    @GetMapping(value = "/selectByStationIdAndCityAndNotCounty")
    public SysResult selectByStationIdAndCityAndNotCounty(String stationid, String city, String county){
        List<SmallScaleStation> smallScaleStations = qxjcService.selectByStationIdAndCityAndNotCounty(stationid, city, county);
        return SysResult.success(smallScaleStations);
    }

    @ApiOperation("根据观测时间段查询站点id，名字，和时间")
    @GetMapping(value = "/selectByObservtimeOfMsgMediumSmallScaleTemp")
    public SysResult selectByObservtimeOfMsgMediumSmallScaleTemp(String startTime, String endTime){
        Date observtimeStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(startTime));
        Date observtimeEnd = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(endTime));
        List<MsgMediumSmallScaleTemp> list = qxjcService.selectByObservtimeOfMsgMediumSmallScaleTemp(observtimeStart, observtimeEnd);
        return SysResult.success(list);
    }

    @ApiOperation("通过站点名字查询站点id")
    @GetMapping(value = "/selectByStationNameOfEnviroStation")
    public SysResult selectByStationNameOfEnviroStation(String stationName){
        List<EnviroStation> list = qxjcService.selectByStationNameOfEnviroStation(stationName);
        return SysResult.success(list);
    }

    @ApiOperation("根据观测时间段查询站点id，名字，和(去重)时间")
    @GetMapping(value = "/selectByObservtimeDsitOfMsgMediumSmallScaleTemp")
    public SysResult selectByObservtimeDsitOfMsgMediumSmallScaleTemp(String startTime, String endTime){
        Date observtimeStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(startTime));
        Date observtimeEnd = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(endTime));
        List<MsgMediumSmallScaleTemp> list = qxjcService.selectByObservtimeDsitOfMsgMediumSmallScaleTemp(observtimeStart, observtimeEnd);
        return SysResult.success(list);
    }

    @ApiOperation("根据站点名字和天气类型查询观测时间")
    @GetMapping(value = "/selectByWeatherTypeAndStationNameOfImportantWeather")
    public SysResult selectByWeatherTypeAndStationNameOfImportantWeather(String weathertype, String stationname){
        List<ImportantWeather> list = qxjcService.selectByWeatherTypeAndStationNameOfImportantWeather(weathertype, stationname);
        return SysResult.success(list);
    }

    @ApiOperation("根据天气类型，站点名字和观测时间段查询重要天气信息")
    @GetMapping(value = "/selectByWeatherTypeAndStationNameAndObservetimeOfImportantWeather")
    public SysResult selectByWeatherTypeAndStationNameAndObservetimeOfImportantWeather(String startTime, String endTime, String weathertype, String stationname){
        Date observtimeStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(startTime));
        Date observtimeEnd = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(endTime));
        List<ImportantWeather> list = qxjcService.selectByWeatherTypeAndStationNameAndObservetimeOfImportantWeather(observtimeStart, observtimeEnd, weathertype,stationname);
        return SysResult.success(list);
    }

    @ApiOperation("根据时间段获取雾霾能见度")
    @GetMapping(value = "/selectByTimePeriodOfMsgMediumSmallScale")
    public SysResult selectByTimePeriodOfMsgMediumSmallScale(String startTime, String endTime){
        Date observtimeStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(startTime));
        Date observtimeEnd = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(endTime));
        List<MsgMediumSmallScale> list = qxjcService.selectByTimePeriodOfMsgMediumSmallScale(observtimeStart, observtimeEnd);
        return SysResult.success(list);
    }

    @ApiOperation("获取所有自动站实况主表信息")
    @GetMapping(value = "/getAllOfMsgMediumSmallScale")
    public SysResult getAllOfMsgMediumSmallScale(){
        List<MsgMediumSmallScale> list = qxjcService.getAllOfMsgMediumSmallScale();
        return SysResult.success(list);
    }

    @ApiOperation("区域自动站站点表信息")
    @GetMapping(value = "/getAllOfSmallScaleStation")
    public SysResult getAllOfSmallScaleStation(){
        List<SmallScaleStation> list = qxjcService.getAllOfSmallScaleStation();
        return SysResult.success(list);
    }

    @ApiOperation("根据时间段要素和站点查询自动站实况主表")
    @GetMapping(value = "/selectByTimePeriodAndElementAndStationIdOfMsgMediumSmallScale")
    public SysResult selectByTimePeriodAndElementAndStationIdOfMsgMediumSmallScale(
            String startTime, String endTime, String element, String stationname){
        Date observtimeStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(startTime));
        Date observtimeEnd = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(endTime));
        List<MsgMediumSmallScale> list = qxjcService.selectByTimePeriodAndElementAndStationIdOfMsgMediumSmallScale(
                observtimeStart, observtimeEnd, element, stationname);
        return SysResult.success(list);



    }











}
